const oldArrProto = Array.prototype

const methods = ['push', 'pop', 'shift', 'unshift', 'splice']

const ArrayProto = Object.create(oldArrProto)

methods.forEach(method => {
    ArrayProto[method] = function(...arg) {
        let res = oldArrProto[method].apply(this, arg)

        let inserted

        switch(method) {
            case 'push':
                inserted = arg;
                break;
            case 'unshift':
                inserted = arg;
                break;
            case 'splice':
                inserted = arg.slice(2)
                break;
        }

        if(inserted){
            // 新增的数据进行监听
            let observe = this.__ob__;
            observe.observeArray(inserted)
        }

        this.__ob__.dep.notify()

        return res
    }
})

export default ArrayProto
